Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
Simple way to display "years of service" in html/javascript

I am trying to display a number for years of service on a website. Essentially I thought I could put in a start date and current date to have an output of the years in between.

I can gt the current year using the following code but am unsure how to calculate the deference

document.write(2010) + (/\d{4}/.exec(Date())[0])

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Just subtract 2010 from the current year and concatenate the string:

document.write((/\d{4}/.exec(Date())[0]) - 2010 + ' years of service')

Although an easier way to get the year is to use Date.getFullYear():

document.write(new Date().getFullYear() - 2010 + ' years of service')

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use Date functions to extract components of time. To get year you can use something like:

today = new Date();
year = today.getFullYear();

To calculate difference between years (year value is number):

d = year - 2010;
about 4 years ago · Juan Pablo Isaza Relatório

0

You can get like this

document.write(new Date().getFullYear() - 2010)

document.write(new Date().getFullYear() - 2010)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda